<form class="filter-bar">
  <FreetextFilter
    @onsearch={{action onsearch}}
    @value={{search}}
    @placeholder="Search"
  />
  <div class="filters">
    <PopoverSelect
      @position="left"
      @onchange={{action onfilter.access}}
      @multiple={{true}}
    as |components|>
      <BlockSlot @name="selected">
        <span>
          Permissions
        </span>
      </BlockSlot>
      <BlockSlot @name="options">
{{#let components.Optgroup components.Option as |Optgroup Option|}}
        <Option @value="allow" @selected={{contains 'allow' filter.accesses}}>Allow</Option>
        <Option @value="deny" @selected={{contains 'deny' filter.accesses}}>Deny</Option>
{{/let}}
      </BlockSlot>
    </PopoverSelect>
  </div>
  <div class="sort">
    <PopoverSelect
      class="type-sort"
      data-test-sort-control
      @position="right"
      @onchange={{action onsort}}
      @multiple={{false}}
    as |components|>
      <BlockSlot @name="selected">
        <span>
          {{#let (from-entries (array
              (array "Action:asc" "Allow to Deny")
              (array "Action:desc" "Deny to Allow")
              (array "SourceName:asc" "Source: A to Z")
              (array "SourceName:desc" "Source: Z to A")
              (array "DestinationName:asc" "Destination: A to Z")
              (array "DestinationName:desc" "Destination: Z to A")
              (array "Precedence:asc" "Precedence: Ascending")
              (array "Precedence:desc" "Precedence: Descending")
              ))
            as |selectable|
          }}
            {{get selectable sort}}
          {{/let}}
        </span>
      </BlockSlot>
      <BlockSlot @name="options">
{{#let components.Optgroup components.Option as |Optgroup Option|}}
        <Optgroup @label="Permission">
          <Option @value="Action:asc" @selected={{eq "Action:asc" sort}}>Allow to Deny</Option>
          <Option @value="Action:desc" @selected={{eq "Action:desc" sort}}>Deny to Allow</Option>
        </Optgroup>
        <Optgroup @label="Source">
          <Option @value="SourceName:asc" @selected={{eq "SourceName:asc" sort}}>A to Z</Option>
          <Option @value="SourceName:desc" @selected={{eq "SourceName:desc" sort}}>Z to A</Option>
        </Optgroup>
        <Optgroup @label="Destination">
          <Option @value="DestinationName:asc" @selected={{eq "DestinationName:asc" sort}}>A to Z</Option>
          <Option @value="DestinationName:desc" @selected={{eq "DestinationName:desc" sort}}>Z to A</Option>
        </Optgroup>
        <Optgroup @label="Precedence">
          <Option @value="Precedence:asc" @selected={{eq "Precedence:asc" sort}}>Ascending</Option>
          <Option @value="Precedence:desc" @selected={{eq "Precedence:desc" sort}}>Descending</Option>
        </Optgroup>
{{/let}}
      </BlockSlot>
    </PopoverSelect>
  </div>
</form>